<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class tindak_lanjut extends arfaController {

	public function __construct()
	{
		parent::__construct();
		$this->load->helper('general');
		$this->cekLogin();
		$this->load->model('m_tindak_lanjut_model');
		$this->load->model('m_tanya_model');
	}

	// start tindak_lanjut
	public function index()
	{
		$data["tindak_lanjut"]	= $this->m_tindak_lanjut_model->get();
		$data["content"] = $this->load->view("grid_tindak_lanjut",$data,true);
		$data["menu"] 			= "admin";
		$this->load->view('main',$data);
	}

	public function pesan()
	{
		$data["tindak_lanjut"]	= $this->m_tindak_lanjut_model->get();
		$data["message"] 		= "pesan";
		$data["menu"] 			= "admin";
		$data["content"] = $this->load->view("grid_tindak_lanjut",$data,true);
		$this->load->view('main',$data);
	}

	public function form_tindak_lanjut( $id = FALSE )
	{
		$this->form_validation->set_rules("tanggal_dibuat","Tanggal Dibuat","required");
		$this->form_validation->set_rules("deadline","Deadline","required");

		$pertanyaan 				= array("" => "-- Pilih Pertanyaan --");
		$pertanyaan 				+= $this->m_tanya_model->get_key_pertanyaan();
		$data["list_pertanyaan"] 	= $pertanyaan;

		if($this->form_validation->run() == FALSE) {
			if( $id == FALSE ) {
				$data["id"]					= $id;
				$data["content"]			= $this->load->view("form_tindak_lanjut",$data,true);
				$data["menu"] 				= "admin";
				$this->load->view("main",$data);
			} else {
				$data["id"]			= $id;
				$data["value"]		= $this->m_tindak_lanjut_model->get($id);
				$data["content"]	= $this->load->view("form_tindak_lanjut",$data,true);
				$data["menu"] 		= "admin";
				$this->load->view("main",$data);
			}
		} else {
			$tanggal_dibuat	= date('Y-m-d', strtotime($this->input->post("tanggal_dibuat")));
			$deadline		= date('Y-m-d', strtotime($this->input->post("deadline")));
			$pertanyaan 	= $this->input->post("pertanyaan");
			$keterangan		= $this->input->post("keterangan");

			$data = array(
				"tanggal_dibuat" => $tanggal_dibuat,
				"deadline" => $deadline,
				"ID_PERTANYAAN" => $pertanyaan,
				"keterangan" => $keterangan
			);

			if( $id==FALSE ) {
				$this->m_tindak_lanjut_model->save($data);
			} else {
				$this->m_tindak_lanjut_model->save($data,$id);
			}
			redirect("tindak_lanjut/pesan");
		}
	}
}
	// end tindak_lanjut